//
//  MONumberOfPersonnelViewController.m
//  MobileOffice
//
//  Created by 冰冰 on 2019/8/6.
//  Copyright © 2019 com.idolmedia. All rights reserved.
//

#import "MONumberOfPersonnelViewController.h"
#import "MOCommonUseViewCell.h"
//待办事项
#import "MONumberOfPersonnelOfWaitViewController.h"
//工作任务
#import "MOWorkTaskListViewController.h"
//领导评鉴
#import "MOLaderEvaluationListViewController.h"
//工作自评
#import "MOWorkSelfAssessmentViewController.h"
//工作纪实
#import "MOWorkJiShiViewController.h"

@interface MONumberOfPersonnelViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>

@property(nonatomic,strong)UICollectionView *collectionView;

@property(nonatomic,strong)NSMutableArray *dataArray;

@end

@implementation MONumberOfPersonnelViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initView];
    
    [self requestData];
    
    [self loginNumberPerson];
}

- (void)initView{
    self.title = @"数字人事";
    [self.view addSubview:self.collectionView];
}

-(void)requestData
{
    self.dataArray = [NSMutableArray array];
//    NSArray *nameArr = @[@"待办事项",@"已办事项",@"工作纪实",@"领导评鉴",@"工作自评",@"工作任务"];
//    NSArray *imageArr = @[@"number_daiban",@"number_yiban",@"number_jishi",@"number_lingdao",@"number_ziping",@"number_renwu"];
//    for (int i = 0; i<nameArr.count; i++) {
//        MOCommonUseModel *model = [[MOCommonUseModel alloc]init];
//        model.nameStr = nameArr[i];
//        model.imageStr = imageArr[i];
//        model.itemIndex = i;
//        model.typeStr = @"3";
//        //        model.countStr = @"99";
//        [self.dataArray addObject:model];
//    }
    
    
    NSArray *nameArr = @[@"工作纪实",@"工作自评"];
    NSArray *imageArr = @[@"number_jishi",@"number_ziping"];
    for (int i = 0; i<nameArr.count; i++) {
        MOCommonUseModel *model = [[MOCommonUseModel alloc]init];
        model.nameStr = nameArr[i];
        model.imageStr = imageArr[i];
        model.itemIndex = i;
        model.typeStr = @"3";
        //        model.countStr = @"99";
        [self.dataArray addObject:model];
    }
    
    [self.collectionView reloadData];
}

-(void)loginNumberPerson
{
    NSString *userId = [MOUser sharedMOUser].userName;
    NSString *url = [NSString stringWithFormat:@"%@?userId=%@&authorization=%@",SZRSDBSX_QUERYSZRSUSERINFO_URL,userId,[NSString URLEncodedString:[MOUser sharedMOUser].token]];
    
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [PPNetworkHelper POST:url parameters:@{} success:^(id responseObject) {
        NSLog(@"数字人事登录：%@",responseObject);
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        if ([responseObject isKindOfClass:[NSDictionary class]]) {
            
            if ([responseObject[@"result"] isKindOfClass:[NSArray class]]) {
                
                NSDictionary *dataDic = responseObject[@"result"][0];
                
                UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];
                [button setTitle:[NSString stringWithFormat:@" %@",dataDic[@"xm"]] forState:UIControlStateNormal];
                [button setImage:IMAGE(@"setUp_userInfo") forState:UIControlStateNormal];
                [button setTitleColor:KBlueColor_2C94FF forState:UIControlStateNormal];
                button.titleLabel.font = FONT_SIZE(14);
                
                UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:button];
                self.navigationItem.rightBarButtonItem = rightItem;
                
                if ([dataDic.allKeys containsObject:@"fgryxm"]) {
                    MOCommonUseModel *model = [[MOCommonUseModel alloc]init];
                    model.nameStr = @"领导评鉴";
                    model.imageStr = @"number_lingdao";
                    model.itemIndex = 2;
                    model.typeStr = @"3";
                    [self.dataArray addObject:model];
                    [self.collectionView reloadData];
                }
                
            }
        }
    } failure:^(NSError *error) {
        NSLog(@"数字人事登录：%@",[error localizedDescription]);
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        [[ADShowMessage shareShowMessage]showTextOnly:[error localizedDescription] showInView:self.view];
    }];
}

#pragma mark -UICollectionViewDataSource,UICollectionViewDelegate
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return self.dataArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    MOCommonUseViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    cell.model = self.dataArray[indexPath.item];
    return cell;
    
}
//定义每个UICollectionView 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    return CGSizeMake(SCREEN_WIDTH/3, SCREEN_WIDTH/3);
    
}

-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    
    return UIEdgeInsetsMake(0, 0, 0, 0);
    
}

//定义每个UICollectionView 横向的间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    
    return 0;
}

//定义每个UICollectionView 竖向的间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    
    return 0;
}

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
    
    return CGSizeMake(0,0);
    
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
//    if (indexPath.item==0) {//待办事项
//        MONumberOfPersonnelOfWaitViewController *vc = [[MONumberOfPersonnelOfWaitViewController alloc]init];
//        [self.navigationController pushViewController:vc animated:YES];
//    }else if (indexPath.item==1){//已办事项
//
//    }else if (indexPath.item==2){//工作纪实
//
//    }else if (indexPath.item==3){//领导评鉴
//        MOLaderEvaluationListViewController *vc = [[MOLaderEvaluationListViewController alloc]init];
//        [self.navigationController pushViewController:vc animated:YES];
//    }else if (indexPath.item==4){//工作自评
//        MOWorkSelfAssessmentViewController *vc = [[MOWorkSelfAssessmentViewController alloc]init];
//        [self.navigationController pushViewController:vc animated:YES];
//    }else if (indexPath.item==5){//工作任务
//        MOWorkTaskListViewController *vc = [[MOWorkTaskListViewController alloc]init];
//        [self.navigationController pushViewController:vc animated:YES];
//    }
    
    if (indexPath.item==0) {
        MOWorkJiShiViewController *vc = [[MOWorkJiShiViewController alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }else if (indexPath.item==1){
        MOWorkSelfAssessmentViewController *vc = [[MOWorkSelfAssessmentViewController alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }else{
        MOLaderEvaluationListViewController *vc = [[MOLaderEvaluationListViewController alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }
}


#pragma mark -懒加载
-(UICollectionView *)collectionView
{
    if (!_collectionView) {
        
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
        layout.scrollDirection = UICollectionViewScrollDirectionVertical;
        
        _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT-StatusBarAndNavigationBarHeight) collectionViewLayout:layout];
        _collectionView.backgroundColor = [UIColor whiteColor];
        _collectionView.showsVerticalScrollIndicator = NO;
        _collectionView.alwaysBounceVertical = YES;
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        
        [_collectionView registerClass:[MOCommonUseViewCell class] forCellWithReuseIdentifier:@"cell"];
        
    }
    return _collectionView;
}

@end
